package com.cy.pj.ajax.controller;

import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RestController
public class AjaxController {

    private List<String> list = new ArrayList<>();

    @PostMapping("doSave")
    public String doSave(String name) {
        list.add(name);
        return "save ok";
    }

    @GetMapping("doAjaxGet")
    public String doAjaxGet() throws InterruptedException{
        System.out.println("--doAjaxGet--");
        Thread.sleep(5000);
        return "Ajax Get Request Result";
    }

    @GetMapping("doCheck")
    @CrossOrigin
    public String doCheck(String name) {
        return list.contains(name) ? name + "已存在" : "";
    }
}
